<?php
/**
 * Created by PhpStorm.
 * User: alinejun
 * Date: 2019/1/7
 * Time: 21:43
 */
namespace app\admin\controller;
use app\common\controller\ControllerBase;
use think\Db;

class Order extends AdminBase{
    /**
     * 用户列表
     */
    protected $order;
    public function _initialize()
    {
        $this->order = new \app\common\model\Order();
        parent::_initialize();
    }
    public function index()
    {
        $seacch_data = input('param.search_data');
        $where = [];
        !empty($seacch_data) and   $where =['order_no'=>['like','%'.$seacch_data.'%']];
        $list = $this->order->search($where);
        $this->assign('list', $list);
        return $this->fetch('index');
    }

    public function del()
    {
        $where['id'] = input('id');
        $res = $this->order->del($where,'status',-1);
        if($res){
            return $this->success('删除成功');
        }else{
            return $this->error('删除失败');
        }
    }

    public function setStatus()
    {
        $this->jump($this->logicAdminBase->setStatus('Order', $this->param));
    }

    public function add()
    {
        $data = input('param.');
        $res = $this->order->editOrder($data);

        IS_POST && $this->jump($res);
        /*  $this->assign('info',$info);*/
        return $this->fetch('add');
    }

    public function edit(){
        if(IS_GET){
            $where = input('param.');
            $info = $this->order->getOrderById($where);

            $address = (new \app\common\model\Address())->getAddressById(['id'=>$info['address_id']]);
            $info['addressInfo'] =$address ;
            $this->assign('info',$info);
            return $this->fetch('add');
        }
        $data = input('param.');
        $res = $this->order->editOrder($data);
        if($res){
            return $this->success('修改成功','index');
        }
    }

}
